package com.pengtu.entity.contract;

import java.util.Comparator;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Where;

import com.pengtu.entity.IdEntity;
import com.pengtu.entity.app.Attachment;

/**
 * 建设工程检测协议书
 * @author Administrator
 *
 */
@Entity
@Table(name="T_C_CONTRACT_DOCUMENT")
public class Document extends IdEntity {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String pid; //工程ID
	private String remark; //备注
	private String effectiveDate;//有效时间
	private Date signTime;//签订时间
	private String sign;//签订状态
	private String status;//状态
	private Set<Attachment> attachmentSet = new TreeSet<Attachment>(
			new Comparator<Attachment>() {
				@Override
				public int compare(Attachment attFirst, Attachment attSecond) {
					// TODO Auto-generated method stub
					return attFirst.getCreateDate().compareTo(
							attSecond.getCreateDate());
				}
			}); // 附件
	@Column(name="PID")
	public String getPid() {
		return pid;
	}
	public void setPid(String pid) {
		this.pid = pid;
	}

	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	/**
	 * effectiveDate
	 *
	 * @return  the effectiveDate
	 * @since   1.0.0
	 */
	@Column(name="EFFECTIVEDATE")
	public String getEffectiveDate() {
		return effectiveDate;
	}
	/**
	 * @param effectiveDate the effectiveDate to set
	 */
	public void setEffectiveDate(String effectiveDate) {
		this.effectiveDate = effectiveDate;
	}
	
	/**
	 * signTime
	 *
	 * @return  the signTime
	 * @since   1.0.0
	 */
	@Column(name="SIGNTIME")
	public Date getSignTime() {
		return signTime;
	}
	/**
	 * @param signTime the signTime to set
	 */
	public void setSignTime(Date signTime) {
		this.signTime = signTime;
	}
	/**
	 * sign
	 *
	 * @return  the sign
	 * @since   1.0.0
	 */
	@Column(name="SIGN")
	public String getSign() {
		return sign;
	}
	
	/**
	 * @param sign the sign to set
	 */
	public void setSign(String sign) {
		this.sign = sign;
	}
	
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "TABLEID")
	@Where(clause="delFlag = 0")
	public Set<Attachment> getAttachmentSet() {
		return attachmentSet;
	}

	public void setAttachmentSet(Set<Attachment> attachmentSet) {

		this.attachmentSet = attachmentSet;
	}

	@Transient
	public Attachment getAttachment() {
		if (attachmentSet.iterator().hasNext())
			return attachmentSet.iterator().next();
		return new Attachment();
	}

	public void setAttachment(Attachment attachment) {
		attachmentSet.clear();
		attachmentSet.add(attachment);
	}
	/**
	 * status
	 *
	 * @return  the status
	 * @since   1.0.0
	 */
	@Column(name="STATUS")
	public String getStatus() {
		return status;
	}
	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}
	
}
